using System;
using System.Globalization;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Media.Transformation;

namespace AnimationPage.Converters;

public sealed class TransformConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (parameter is not Avalonia.Controls.Dock dock)
            return "translate(0px)";

        return TransformOperations.Parse(dock switch
        {
            Dock.Bottom => $"translateY({value}px)",
            Dock.Top => $"translateY(-{value}px)",
            Dock.Left => $"translateX(-{value}px)",
            Dock.Right => $"translateX({value}px)",
            _ => "translate(0px)",
        });
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}